package com.area.cth.mapper;

import com.area.cth.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where username=#{username}")
    User findByUsername(String username);

    @Insert("insert into user(username,password,create_time,update_time)" +
            " values(#{username},#{password},now(),now())")
    void add(String username, String password);

    @Update("update user set avatar=#{avatar},update_time=now() where id=#{id}")
    void updateAvatar(String avatar, Integer id);

    @Update("update user set nickname=#{nickname},introduction=#{introduction},email=#{email},phone=#{phone},address=#{address},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    @Update("update user set password=#{md5String},update_time=now() where id=#{id}")
    void updatePwd(String md5String, Integer id);

    @Update("update user set background=#{background},update_time=now() where id=#{id}")
    void updateBackground(String background, Integer id);

    @Update("update user set login_time=#{loginTime},update_time=now() where username=#{username}")
    void login(String username, LocalDateTime loginTime);

    @Select("select * from user where id=#{id}")
    User getUserInfoById(Integer id);
}
